/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author USER
 */
public class BDConexFactory {

    private static BDConexFactory oBDConexFactory = null;
    private InitialContext oInitialContext;
    private DataSource oDataSource;

    private BDConexFactory() {
        try {
            oInitialContext = new InitialContext();
            //datasource por defecto que esta configurado en el config.properties

            oDataSource = (DataSource) oInitialContext.lookup("jdbc/viajes");

            System.out.println(":::CONECTO::::");
        } catch (Exception e) {
            System.out.println("BDConexFactory() " + e.getMessage());

        }
    }

    public Connection getConnection() throws SQLException {
        Connection conn = null;
        conn = oDataSource.getConnection();
        return conn;
    }

    public static BDConexFactory getInstance() {
        if (oBDConexFactory == null) {
            oBDConexFactory = new BDConexFactory();
        }
        return oBDConexFactory;
    }
}
